package com.ruoyi.web.controller.schoolDistrict;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.domain.School;
import com.ruoyi.service.ISchoolService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @version 1.0
 * @ClassName
 * @Author DELL
 * @Date 2020/6/22 16:16
 **/

@Controller
@RequestMapping("/school/district")
public class SchoolDistrictController extends BaseController {

    private final String prefix = "pc/school-district";

    @Autowired
    private ISchoolService schoolService;

    @RequiresPermissions("system:school:view")
    @GetMapping()
    public String school()
    {
        return prefix + "/school";
    }

    @GetMapping("/map")
    public String schoolMap(ModelMap map)
    {
        List<School> list = schoolService.selectSchoolList(new School());
        map.put("schoolList",list);
        return prefix + "/school-map";
    }





    /**
     * 查询智慧教育--学校信息列表
     */
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(School eduSchool)
    {
        startPage();
        List<School> list = schoolService.selectSchoolList(eduSchool);
        return getDataTable(list);
    }

    /**
     * 导出智慧教育--学校信息列表
     */
    @Log(title = "智慧教育--学校信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(School eduSchool)
    {
        List<School> list = schoolService.selectSchoolList(eduSchool);
        ExcelUtil<School> util = new ExcelUtil<School>(School.class);
        return util.exportExcel(list, "school");
    }

    /**
     * 新增智慧教育--学校信息
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存智慧教育--学校信息
     */
    @Log(title = "智慧教育--学校信息", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(School eduSchool)
    {
        return toAjax(schoolService.insertSchool(eduSchool));
    }

    /**
     * 修改智慧教育--学校信息
     */
    @GetMapping("/edit/{sid}")
    public String edit(@PathVariable("sid") Long sid, ModelMap mmap)
    {
        School eduSchool = schoolService.selectSchoolById(sid);
        mmap.put("eduSchool", eduSchool);
        return prefix + "/edit";
    }

    /**
     * 修改保存智慧教育--学校信息
     */
    @Log(title = "智慧教育--学校信息", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(School eduSchool)
    {
        return toAjax(schoolService.updateSchool(eduSchool));
    }

    /**
     * 删除智慧教育--学校信息
     */
    @Log(title = "智慧教育--学校信息", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(schoolService.deleteSchoolByIds(ids));
    }

}
